package com.xuecheng.content.controller;

import com.xuecheng.api.content.model.CourseBaseApi;
import com.xuecheng.api.content.model.dto.CourseBaseDTO;
import com.xuecheng.api.content.model.qo.QueryCourseModel;
import com.xuecheng.api.content.model.vo.CourseBaseVO;
import com.xuecheng.common.domain.page.PageRequestParams;
import com.xuecheng.common.domain.page.PageVO;
import com.xuecheng.common.util.SecurityUtil;
import com.xuecheng.content.convert.EntityMapper;
import com.xuecheng.content.service.CourseBaseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程基本信息 前端控制器
 * </p>
 *
 * @author itcast
 */
@Slf4j
@RestController
public class CourseBaseController implements CourseBaseApi {

    @Autowired
    private CourseBaseService courseBaseService;

    /**
     * 查询所有
     *
     * @param params
     * @param model
     * @return
     */
    @Override
    @PostMapping("course/list")
    public PageVO queryCourseList(PageRequestParams params, @RequestBody QueryCourseModel model) {
        Long companyId = SecurityUtil.getCompanyId();
        return courseBaseService.queryCourseList(params, model, companyId);
    }

    /**
     * 添加coursebase课程信息和courseMark收费信息
     *
     * @param vo
     * @return
     */
    @PostMapping("course")
    public CourseBaseDTO creatCourse(@RequestBody CourseBaseVO vo) {
        CourseBaseDTO courseBaseDTO = EntityMapper.INSTANCE.courseBaseVoToCourseBaseDTo(vo);

        Long companyId = SecurityUtil.getCompanyId();
        courseBaseDTO.setCompanyId(companyId);

        return courseBaseService.creatCourse(courseBaseDTO);
    }

    /**
     * 根据课程id查询课程信息
     *
     * @param courseBaseId
     * @return
     */
    @GetMapping("course/{courseBaseId}")
    public CourseBaseDTO updatequeryById(@PathVariable Long courseBaseId) {
        Long companyId = SecurityUtil.getCompanyId();
        return courseBaseService.updatequeryById(courseBaseId, companyId);
    }

    /**
     * 修课程信息
     *
     * @param vo
     * @return
     */
    @PutMapping("course")
    public CourseBaseDTO updateCourseBase(@RequestBody CourseBaseVO vo) {
        CourseBaseDTO courseBaseDTO = EntityMapper.INSTANCE.courseBaseVoToCourseBaseDTo(vo);
        Long companyId = SecurityUtil.getCompanyId();
        courseBaseDTO.setCompanyId(companyId);
        return courseBaseService.updateCourseBase(courseBaseDTO);
    }


    /**
     * 逻辑删除课程信息
     *
     * @param courseBaseId
     */
    @DeleteMapping("course/{courseBaseId}")
    public void deleteCourseBase(@PathVariable Long courseBaseId) {
        Long companyId = SecurityUtil.getCompanyId();
        courseBaseService.deleteCourseBase(courseBaseId, companyId);
    }




}
